
/***********************************************************************
 * Artifact class
 * 
 * Implements the root of the artifact hierarchy
 *
 * Signature:
 *  public void install ();
 *  public void destroy ();
 *  public Coord position ();
 *  public String name ();
 *  public void report (String message);
 *  public void changePosition (Coord target);
 *  public boolean isOrbitable ();
 *  public void takeDamage (int damage);
 *  public abstract char display ();
 *  public abstract String toString ();
 ***********************************************************************/


public abstract class Artifact implements JSON_Saving<Artifact> {

  private String name;
  private Coord position;

  protected Artifact (String n, Coord p) {
    this.name = Util.noSpaces(n);
    this.position = p;
  }
	
  public void install () { 
    Coord size = SpaceGame.map().size();
    SpaceGame.updateMap(Map.merge(Map.artifact(size.xPos(),
					       size.yPos(),this),
				  SpaceGame.map()));
  }	

  public void destroy () {
    SpaceGame.updateMap(SpaceGame.map().removeArtifact(this));
  }
	    

  public Coord position () {
    return this.position;
  }

  public String name () {
    return this.name;
  }

  public void report (String s) {
    if (SpaceGame.isGodMode())
      System.out.println(this.name() + " reports -- " + s);
  }

  public void changePosition (Coord c) {
    if (!c.within(Coord.create(0,0),
		  SpaceGame.map().size().move(-1,-1)))
      throw new IllegalArgumentException("Artifact.changePosition()");
    position = c;
  }

  public boolean isOrbitable () {
    return false;
  }

  public void takeDamage (int d) {
    report("no damage");
  }

  public abstract char display ();

  public abstract String toString ();

  public String jsonString() {
    return "{Artifact:[" + name() + "," + position() + "]}";
  }

  public abstract Artifact fromJSONString(String jsonString);
}


